#! /usr/bin/env node
const fs = require("fs")
const inquirer = require("inquirer")
const { program } = require("commander")
const path = require("path")
program.version("v0.0.1")
    .option("-v,--version", "v1,0,1") 
    .parse(process.argv)
const redir = (dname) => {
    let dpath = path.join(process.cwd(), dname)
    if (!fs.existsSync(dpath)) {
        console.log("不存在这个");
        return
    }
    let stats = fs.statSync(dname)
    if (!stats.isDirectory()) {
        fs.unlinkSync(dpath)
        return
    }
    let ds = fs.readdirSync(dpath)
    if (ds.length > 0) {
        ds.forEach(item => {
            redir(path.join(dname, item))
        })
        fs.rmdirSync(dname)
    }
    if (ds.length === 0) {
        fs.rmdirSync(dname)
    }
}
inquirer.prompt([
    {
        type: "input",
        name: "输入名称"
    },
    {
        type: "confirm",
        name: "删除?"
    }
]).then(res => {
    let dname = res["输入名称"]
    if (res["删除?"]) {
        redir(dname)
    }
})